package com.jwong.example.service.controller;


import com.jwong.example.service.model.Order;
import io.micrometer.core.annotation.Counted;
import io.micrometer.core.annotation.Timed;
import org.springframework.web.bind.annotation.*;

import java.util.Optional;
import java.util.UUID;

@RestController
public class OrderController {

    @GetMapping("/api/order/{id}")
    public Order oneOrder(@PathVariable String id) {
        return new Order(id, UUID.randomUUID().toString(), "iPhone");
    }

    @PostMapping("/api/orders")
    public Order createOrder(@RequestBody(required = false) Order order) {
        return Optional.ofNullable(order).orElse(new Order("", UUID.randomUUID().toString(), "iPad"));
    }

}
